<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Class Mfaq extends MY_Model
{
    public function __construct()
    {
        parent::__construct();
    }
    
    public function indexDb()
    {
        $data = $this->db->query("SELECT * FROM faq ORDER BY id ASC")->result_object();
        return $data;
    }
    
    public function addFaqDb($question,$answer)
    {
        $data = array(
            'question' => $question,
            'answer' => html_entity_decode($answer, ENT_QUOTES, "UTF-8")
        );
        
        $this->db->insert('faq', $data);
        $this->db->update('options', array('content' => time()), "tags = 'time_update_api_static'");
        return 200;
    }
    
    public function getFaqDb($id)
    {
        $data = $this->db->query("SELECT * FROM faq WHERE id = ".$id)->row_object();
        return $data;
    }
    public function editFaqDb($id,$question,$answer)
    {
        $data = array(
            'question' => $question,
            'answer' => html_entity_decode($answer, ENT_QUOTES, "UTF-8")
        );
        
        $this->db->update('faq', $data, "id = ".$id);
        $this->db->update('options', array('content' => time()), "tags = 'time_update_api_static'");
        return 200;
    }
    
    public function deleteFaqDb($id)
    {
        $this->db->delete('faq', array('id' => $id));
        $this->db->update('options', array('content' => time()), "tags = 'time_update_api_static'");
        return 200;
    }
}